package de.neua;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import android.os.Parcel;
import android.os.Parcelable;

public class Entry implements Parcelable {
	// verlängerbar?
	private boolean renewable;
	// Leihfrist
	private GregorianCalendar lendingPeriod;

	public GregorianCalendar getLendingPeriod() {
		return lendingPeriod;
	}

	// wie oft wurde es bereits verlängert?
	private int renewed;
	// StandNummer
	private String name;

	public String getName() {
		return name;
	}
// first constructor
	public Entry(boolean renewable, GregorianCalendar lendingPeriod, int renewed, String name) {
		this.renewable = renewable;
		this.lendingPeriod = lendingPeriod;
		this.renewed = renewed;
		this.name = name;
	}

	// import from parcel
	public Entry(Parcel in) {
		this.renewable = in.readByte() == 1;
		this.lendingPeriod = new GregorianCalendar(in.readInt(), in.readInt(), in.readInt());
		this.renewed = in.readInt();
		this.name = in.readString();
	}

	// required. Don't know why.
	public int describeContents() {
		return 0;
	}

	// export to parcel
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeByte((byte) (renewable ? 1 : 0));
		dest.writeInt(lendingPeriod.get(Calendar.YEAR));
		dest.writeInt(lendingPeriod.get(Calendar.MONTH));
		System.out.println(lendingPeriod.get(Calendar.MONTH));
		dest.writeInt(lendingPeriod.get(Calendar.DATE));
		dest.writeInt(renewed);
		dest.writeString(name);
	}

	// also required
	public static final Parcelable.Creator<Entry> CREATOR = new Parcelable.Creator<Entry>() {
		public Entry createFromParcel(Parcel in) {
			return new Entry(in);
		}

		public Entry[] newArray(int size) {
			return new Entry[size];
		}
	};

}
